#include <math.h>
#include "3D.h"

GridMeshXZ::GridMeshXZ(float cellSize_in, int cellsX_in, int cellsZ_in) 
: cellSize(cellSize_in), cellsX(cellsX_in), cellsZ(cellsZ_in), nTris(2 * (cellsX_in * cellsZ_in)), 
  nVerts(cellsX_in * cellsZ_in + cellsX_in + cellsZ_in + 1), indexSize(nTris * 3)
{
    verts = new Vec3[nVerts];
    // Center grid on origin.
    float minX  = -(float)cellsX * cellSize * 0.5f;
    float minZ  = -(float)cellsZ * cellSize * 0.5f;

    for (int zCell = 0; zCell <= cellsZ; ++zCell)
    {
        for (int xCell = 0; xCell <= cellsX; ++xCell)
        {
            verts[zCell + xCell] = Vec3(minX + xCell * cellSize, 0.f, minZ + zCell * cellSize);
        }
    }
    verts[nVerts - 1] = Vec3(-minX, 0.f, -minZ);

    index = new int[nTris];
    for (int i = 0; i < nTris; ++i)
    {
        int rowNumber = 1 + i / cellsX;
        int columnNumer = 1 + (cellsX - i % (cellsX - 1))
    }

    
}

void GridMeshXZ::allocVertexBuffer(float cellSize, int cellsX, int cellsZ)
{
    
}

GridMeshXZ::~GridMeshXZ()
{
    delete[] verts;
    delete[] index;
}

Vec3 & GridMeshXZ::operator[](int i)
{
    int vertIndex = index[i];
    return verts[vertIndex];
}